import axios from '@/utils/axios'

// 请求首页的数据，入参：{ size, page, cate, hot }
export const getGoodList = params => axios ({
  url: '/goods/list',
  method: 'get',
  params
})

// 获取左边栏的数据请求
const getCategory = params => axios({
  url: '/goods/cates',
  method: 'get',
  params
})

// 获取商品详情
// 入参：{ id }
const getGoodDetail = params => axios({
  url: '/goods/details',
  method: 'get',
  params
})

// 加入购物车 入参：{ num, good_id } 请求方式为post
const addCart = data => axios({
  url: '/cart/add',
  method: 'post',
  data
})

// 购物车的商品列表
const getCartList = params => axios({
  url: '/cart/list',
  method: 'get',
  params
})

// 删除商品：在后端做的操作是直接改变商品的状态，并非移出商品
// 入参 { id }
const removeGoods = params => axios({
  url: '/cart/del',
  method: 'get',
  params
})

// 更新购物车商品数据
// 入参： {id, num} post请求
const updateGoods = data => axios({
  url: '/cart/update',
  method: 'post',
  data
})

// 提交购物车
// 入参： { goods }  是购物车列表项_id组件成的字符串
const updateCart = data => axios({
  url: '/cart/order',
  method: 'post',
  data
})

const getBanner = params => axios({
  url: '/banner/list',
  method: 'get',
  params
})

export default {
  getGoodList,
  getGoodDetail,
  getCategory,
  addCart,
  getCartList,
  removeGoods,
  updateGoods,
  updateCart,
  getBanner
}